package com.ruoyi.system.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.system.domain.MiniOrder;
import com.ruoyi.system.domain.dto.SysHomeControllerDTO;
import com.ruoyi.system.domain.vo.HomeStatisticsVO;
import com.ruoyi.system.service.MiniLoginLogService;
import com.ruoyi.system.service.MiniUserService;
import com.ruoyi.system.service.SysHomeService;
import com.ruoyi.system.service.h5.MiniOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.math.RoundingMode;

@Service
public class SysHomeServiceImpl implements SysHomeService {
    @Autowired
    private MiniLoginLogService miniLoginLogService;
    @Autowired
    private MiniOrderService miniOrderService;
    @Override
    public HomeStatisticsVO statistics(SysHomeControllerDTO dto) {
        HomeStatisticsVO vo = miniLoginLogService.selectStatisticsInfo(dto.getStartTime(),dto.getEndTime());
        if (vo.getVisitCount()==null || vo.getVisitCount()==0){
            return vo;
        }
        HomeStatisticsVO vo2 = miniOrderService.selectStatisticsInfo(dto.getStartTime(),dto.getEndTime());
        vo.setVipCount(vo2.getVipCount());
        vo.setOrderAmount(vo2.getOrderAmount());
        vo.setTransformationRate(BigDecimal.valueOf(vo.getVipCount()).divide(BigDecimal.valueOf(vo.getVisitCount()),2, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100)));
        return vo;
    }
}
